<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/22 0022
 * Time: 9:53
 */

namespace app\admin\controller;


use think\Controller;

class Distri extends Controller
{
    public function index(){
        $data = db("distri")->select();
        $this->assign([
            'data' => $data
        ]);
        return view("index");
    }
    public function add(){
        if(request()->post()){
            $params = request()->except('image');
            $file = request()->file('image');
            $info=$file->move( './static/images');
            $filename=str_replace("\\","/",$info->getSaveName());
            $image = '/static/images/'.$filename;
            $data = [
                'image' => $image,
                'name' => $params['name'],
                'tel' => $params['tel'],
                'xing' => $params['xing'],
                'addres' => $params['addres'],
                'uptime' => date("Y-m-d H:i:s")
            ];
//            return $data;
            $row = db("distri")->insert($data);
            if($row){
                return 200;
            }else{
                return -1;
            }
        }
        return view("add");
    }
    public function delete(){
        $id = input("id");
        $del = db("distri")->delete($id);
        if($del){
            return 200;
        }else{
            return -1;
        }
    }
}